﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace Adams.Admin.Presentation.Controllers
{
    [EnsureSsl]
    public class SecurityController : Controller
    {
        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        public JsonResult Login(Adams.Admin.DataTransfer.Security.Login.LoginInput input)
        {
            var model = Business.Security.Login.TryLogin(input);

            if (model.IsValid)
            {
                FormsAuthentication.SetAuthCookie(model.UserID.ToString(), input.Remember.ToBool());
            }

            return Json(model);
        }

        public ActionResult Logout()
        {
            FormsAuthentication.SignOut();
            return Redirect("/Security/Login");
        }

        public ActionResult Forgot(Adams.Admin.DataTransfer.Security.Forgot.PageLoadInput input)
        {
            var model = Business.Security.Forgot.PageLoad(input);
            return View(model);
        }

        public JsonResult TryForgot(Adams.Admin.DataTransfer.Security.Forgot.FormInput input)
        {
            var model = Business.Security.Forgot.TryPasswordReset(input);
            return Json(model);
        }

        public ActionResult ForgotComplete(Adams.Admin.DataTransfer.Security.Forgot.CompletePageLoad input)
        {
            var model = Business.Security.Forgot.CompletePageLoad(input);
            return View(model);
        }

        public ActionResult Signup()
        {
            var model = Business.Security.Signup.PageLoad();
            return View(model);
        }

        public JsonResult TrySignup(Adams.Admin.DataTransfer.Security.Signup.FormInput input)
        {
            var model = Business.Security.Signup.TrySignup(input);
            return Json(model);
        }

        public ActionResult SignupComplete(Adams.Admin.DataTransfer.Security.Signup.CompletePageLoad input)
        {
            var model = Business.Security.Signup.PageLoad(input);
            return View(model);
        }
    }
}
